﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 会员卡管理系统
{
    public partial class Leavefrm : Form
    {
        public Leavefrm()
        {
            InitializeComponent();
        }
        Vipclass.tb_viphouseinfo Leaveinfo = new Vipclass.tb_viphouseinfo();
        Vipclass.tbVipHouseMenthod Leavementhod = new Vipclass.tbVipHouseMenthod();


        private void Leavefrm_Load(object sender, EventArgs e)
        {
            Leavementhod.tbLeavefoFill(lvHouse, imageList1);
            
        }

        private void lvHouse_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(lvHouse.SelectedItems.Count>0)
            {
                string str = lvHouse.SelectedItems[0].Text;
                Leaveinfo= Leavementhod.tbLeavetoshow(str);
                labvipid.Text = Leaveinfo.Strvipid;
                labhouseid.Text = Leaveinfo.Strhouseid;
                labstaydate.Text = Leaveinfo.Dtusedate.ToString();
                labvipidcard.Text = Leaveinfo.Strvipidcard;
                labvipname.Text = Leaveinfo.Strvipname;
            }
            timer1.Enabled = true;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Leavementhod.tbLezvefoFind(lvHouse, imageList1, textBox1.Text);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                string[] str = null;
                string[] str1 = null;
                lableavedate.Text = DateTime.Now.ToString();
                str = (DateTime.Now - Leaveinfo.Dtusedate).ToString().Split('.');
                str1 = str[1].Split(':');
                labdate.Text = str[0] + "天" + str1[0] + "时" + str1[1] + "分" + str1[2] + "秒";
            }
            catch
            {
                labdate.Text = "";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Leaveinfo.Dtleavedate = DateTime.Now;
            Leaveinfo.Strdate = labdate.Text;
            if (Leavementhod.tbhousefoLeave(labhouseid.Text) == 1)
            {
                if (Leavementhod.tbWriteRecord(Leaveinfo) == 1)
                {
                    MessageBox.Show("欢迎下次光临！", "退房成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("退房失败！", "错误");
                    this.Close();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
